package com.bos.controller;

import com.bos.dao.TahunDAO;
import com.bos.domain.Tahun;
import com.bos.editor.TahunEditor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by IntelliJ IDEA.
 * User: Latief
 * Date: 3/17/11
 * Time: 8:29 PM
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class TahunController {

    private TahunDAO tahunDAO;

/* --------------------- Getter and Setter ---------------------*/

    @Autowired
    public void setTahunDAO(TahunDAO tahunDAO) {
        this.tahunDAO = tahunDAO;
    }

/* -------------------------- Other Methods -------------------------- */

    @RequestMapping(value = "/tahun", method = RequestMethod.GET)
    public String index(ModelMap modelMap) {
        modelMap.addAttribute("data", tahunDAO.getAll());
        return "tahun/index";
    }

    @RequestMapping(value = "/tahun/{id}", method = RequestMethod.GET)
    public String show(ModelMap modelMap, @PathVariable("id") Tahun tahun) {
        modelMap.addAttribute("data", tahun);

        return "tahun/show";
    }

    @InitBinder
    protected void initBinder(WebDataBinder binder) throws Exception {
        binder.registerCustomEditor(Tahun.class, new TahunEditor(tahunDAO));
    }

}
